﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using PowerCreator.LMS.Common.Script;
using PowerCreator.LMS.Web.DL.Project;
using PowerCreator.LMS.DL.Project.Entity;
using PowerCreator.LMS.Web.Catalog;
using PowerCreator.LMS.Web.Course;
using PowerCreator.LMS.Common.Utils;
using Telerik.WebControls;

public partial class sysadmin_DL_Project_SetClassLevel : PowerCreator.LMS.Web.Base.WebBasePage
{
    protected string ClassName = string.Empty;
    private VOTOClass voClass = new VOTOClass();
    TOClass objClass = new TOClass();
    VOTOUserOfClass vo = new VOTOUserOfClass();
    TOUserOfClass obj = new TOUserOfClass();

    protected void Page_Load(object sender, EventArgs e)
    {
        //if (IsLicensed(PowerCreator.LMS.Action.Core.ActionInfo.AddJob))
        //{
        //    Script.RedirectURL(GetRefUrl());
        //}
        int CUID = 0;
        int CID = 0;
        if (Request.QueryString["CUID"] != null)
        {
            CUID = int.Parse(Request.QueryString["CUID"].ToString());
            ViewState["CUID"] = CUID.ToString();

        }
        if (Request.QueryString["CID"] != null)
        {
            CID = int.Parse(Request.QueryString["CID"].ToString());
            ViewState["CID"] = CID.ToString();

        }
        if (!IsPostBack)
        {
            InitPage();

            BinderForm(CUID);

        }
    }
    protected override void InitPage()
    {
        btnSave.Text = GetLanageValueByKey("btn_Save", PowerCreator.LMS.Language.LanagetItemType.Page);
        btnReset.Text = GetLanageValueByKey("btn_Reset", PowerCreator.LMS.Language.LanagetItemType.Page);
        base.InitPage();
    }


   

    private void BinderForm(int id)
    {
        vo = obj.Load(id);
        if (vo.TrainScore != null)
            txt_Score.Text = vo.TrainScore.ToString();
        if (int.Parse(txt_Score.Text) < 0)
            txt_Score.Text = "0";
        txt_Content.Text = vo.TrainSummarize;
        txt_level.Text = vo.TrainLevel;

        VOTOClass vocla = new VOTOClass();
        TOClass objcla = new TOClass();
        vocla = objcla.Load(vo.ClassID);
        lbl_Class.Text = vocla.Name;

        VOTOLearner vol = new VOTOLearner();
        TOLearner objl = new TOLearner();
        vol = objl.Load(vo.UserID);
        lbl_Name.Text = vol.Name;
    }

    private bool CheckPageData()
    {
        try 
        {
            int score = 0;
            if (txt_Score.Text.Length > 0)
                score = int.Parse(txt_Score.Text);
            if (score < 0 || score > 100)
            {
                lbl_msg_Error.Text = "<br />分数必须为0~100之间的整数；";
                return false;
            }

        }
        catch (Exception e)
        {
            lbl_msg_Error.Text = "<br />分数必须为数字；" ;
            return false;
        }
        return true;
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {

        if (ViewState["CUID"] != null)
        {
            if (!CheckPageData()) return;

            vo = obj.Load(int.Parse(ViewState["CUID"].ToString()));
            int score = 0;
            if (txt_Score.Text.Length > 0)
                score = int.Parse(txt_Score.Text);
            vo.TrainScore = score;
            vo.TrainLevel = txt_level.Text;
            vo.TrainSummarize = txt_Content.Text;
            if (vo.AddSummarizeTime == null)
                vo.AddSummarizeTime = DateTime.Now;

            obj.Update(vo);
            string url = "ManageClassLevel.aspx?CID=" + ViewState["CID"].ToString();
            Script.RedirectURL(url);
        }
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        string url = "ManageClassLevel.aspx?CID=" + ViewState["CID"].ToString();
        Script.RedirectURL(url);
    }

}